
$(function () {
    index_echarts_1();
    index_echarts_2();
    index_echarts_3();
    index_echarts_4();
    function index_echarts_1() {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('indexecharts1'));
        option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {type: 'shadow'}
            },
            toolbox: {
                feature : {
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            grid: {
                left: '3%', right: '4%', bottom: '3%', containLabel: true
            },
            xAxis: [
                {type: 'category', data: [],
                    axisTick: {alignWithLabel: true,
                        axisTick: { //关键设置，坐标轴刻度也不显示
                            show: false},}}
            ],
            yAxis: [
                {type: 'value',
                    axisLine: { //关键设置，不显示X轴线条
                        show: false},}
            ],
            series: [
                {name: '数量', type: 'bar',
                    itemStyle: {
                        normal: {
                            color: function(params) {
                                // 给出颜色组
                                var colorList = ['#A6A6A6','#1cc09f','#A6A6A6','#1cc09f','#A6A6A6','#1cc09f','#A6A6A6','#1cc09f','#A6A6A6','#1cc09f'];
                                return colorList[params.dataIndex]
                            },
                        }
                    },
                    data: []
                }
            ]
        };
        // 定义x、y轴数据数组
        var searchURL = window.location.search;
        searchURL = searchURL.substring(1, searchURL.length);
        var index = searchURL.split("=")[1];
        var job_names=[];
        var job_name_nums=[];
        //请求后台数据
        $.ajax({
            type : "post",
            async : true,
            url: "/index/job_name/"+index,
            dataType : "json",
            contentType: "application/json",
            success: function(res){
                console.log(res);
                for (var i = 0; i < res.length ; i++) {
                    job_names.push(res[i].job_name);
                    job_name_nums.push(res[i].job_name_num);
                }
                myChart.setOption({
                    xAxis: {
                        data: job_names
                    },
                    series: [{
                        // 根据名字对应到相应的系列
                        name: '数量',
                        data: job_name_nums
                    }]
                });
            }
        });

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }
    function index_echarts_2() {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('indexecharts2'));

        option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            toolbox: {

                feature : {
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: [],
                    axisTick: {
                        alignWithLabel: true,
                        axisTick: { //关键设置，坐标轴刻度也不显示
                            show: false
                        },
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    axisLine: { //关键设置，不显示X轴线条
                        show: false
                    },
                }
            ],
            series: [
                {
                    name: '数量',
                    type: 'bar',
                    itemStyle: {
                        normal: {
                            color: function(params) {
                                // 给出颜色组
                                var colorList = ['#1cc09f','#A6A6A6','#1cc09f','#A6A6A6','#1cc09f','#A6A6A6','#1cc09f','#A6A6A6','#1cc09f','#A6A6A6'];
                                return colorList[params.dataIndex]
                            },
                        }
                    },
                    data: []
                }
            ]
        };
        // 定义x、y轴数据数组
        var searchURL = window.location.search;
        searchURL = searchURL.substring(1, searchURL.length);
        var index = searchURL.split("=")[1];
        var workareas=[];
        var workarea_nums=[];
        //请求后台数据
        $.ajax({
            type : "post",
            async : true,
            url: "/index/workarea/"+index,
            dataType : "json",
            contentType: "application/json",
            success: function(res){
                console.log(res);
                for (var i = 0; i < res.length ; i++) {
                    workareas.push(res[i].workarea);
                    workarea_nums.push(res[i].workarea_num);
                }
                myChart.setOption({
                    xAxis: {
                        data: workareas
                    },
                    series: [{
                        // 根据名字对应到相应的系列
                        name: '数量',
                        data: workarea_nums
                    }]
                });
            }
        });

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }
    function index_echarts_3() {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('indexecharts3'));

        option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            color:['#A6A6A6','#1cc09f'],
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            legend: {
                orient: "horizontal",
                left: "12%",
                data: ['minmoney','avgmoney','maxmoney',]
            },
            toolbox: {
                feature : {
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                axisTick: {
                    alignWithLabel: true,
                    axisTick: { //关键设置，坐标轴刻度也不显示
                        show: false
                    },
                },
                data: []
            },
            yAxis: {
                type: 'value',
                axisLine: { //关键设置，不显示X轴线条
                    show: false
                },
            },
            series: [
                {
                    name: 'minmoney',
                    type: 'line',
                    stack: 'Total',
                    smooth: true,
                    lineStyle:{
                        normal:{
                            width: 3,
                            borderColor:'black'
                        }
                    },
                    itemStyle: {
                        normal: {
                            borderColor: '#000000',//拐点边框颜色
                            borderWidth: 1//拐点边框大小
                        }
                    },
                    data: []
                },
                {
                    name: 'avgmoney',
                    type: 'line',
                    stack: 'Total',
                    smooth: true,
                    lineStyle:{
                        normal:{
                            width: 3,
                            borderColor:'black'
                        }
                    },
                    itemStyle: {
                        normal: {
                            borderColor: '#000000',//拐点边框颜色
                            borderWidth: 1//拐点边框大小
                        }
                    },
                    data: []
                },
                {
                    name: 'maxmoney',
                    type: 'line',
                    stack: 'Total',
                    smooth: true,
                    lineStyle:{
                        normal:{
                            width: 3,
                            borderColor:'red'
                        }
                    },
                    itemStyle: {
                        normal: {
                            borderColor: '#000000',//拐点边框颜色
                            borderWidth: 1//拐点边框大小
                        }
                    },
                    data: []
                },
            ]
        };
        // 定义x、y轴数据数组
        var searchURL = window.location.search;
        searchURL = searchURL.substring(1, searchURL.length);
        var index = searchURL.split("=")[1];
        var job_names=[];
        var avg_minmoneys=[];
        var avg_avgmoneys=[];
        var avg_maxmoneys=[];
        //请求后台数据
        $.ajax({
            type : "post",
            async : true,
            url: "/index/job_name_money/"+index,
            dataType : "json",
            contentType: "application/json",
            success: function(res){
                console.log(res);
                for (var i = 0; i < res.length ; i++) {
                    job_names.push(res[i].job_name);
                    avg_minmoneys.push(res[i].avg_minmoney);
                    avg_avgmoneys.push(res[i].avg_avgmoney);
                    avg_maxmoneys.push(res[i].avg_maxmoney);
                }
                myChart.setOption({
                    xAxis: {
                        data: job_names
                    },
                    series: [{
                        // 根据名字对应到相应的系列
                        name: 'minmoney',
                        data: avg_minmoneys
                    },
                        {
                            // 根据名字对应到相应的系列
                            name: 'avgmoney',
                            data: avg_avgmoneys
                        },
                        {
                            // 根据名字对应到相应的系列
                            name: 'maxmoney',
                            data: avg_maxmoneys
                        },
                    ]
                });
            }
        });
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }
    function index_echarts_4() {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('indexecharts4'));

        option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            legend: {
                orient: "horizontal",
                left: "12%",
                data: ['minmoney','avgmoney','maxmoney',]
            },
            color:['#A6A6A6','#1cc09f'],
            toolbox: {
                feature : {
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    boundaryGap: false,
                    data: []
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    axisLine: { //关键设置，不显示X轴线条
                        show: false
                    }
                },
            ],
            series: [
                {
                    name: 'Minmoney',
                    type: 'line',
                    stack: 'Total',
                    areaStyle: {},
                    emphasis: {
                        focus: 'series'
                    },
                    smooth: true,
                    lineStyle:{
                        normal:{
                            width: 3,
                        }
                    },
                    itemStyle: {
                        normal: {
                            borderColor: '#000000',//拐点边框颜色
                            borderWidth: 1//拐点边框大小
                        }
                    },
                    data: []
                },
                {
                    name: 'Avgmoney',
                    type: 'line',
                    stack: 'Total',
                    areaStyle: {},
                    emphasis: {
                        focus: 'series'
                    },
                    smooth: true,
                    lineStyle:{
                        normal:{
                            width: 3,
                        }
                    },
                    itemStyle: {
                        normal: {
                            borderColor: '#000000',//拐点边框颜色
                            borderWidth: 1//拐点边框大小
                        }
                    },
                    data: []
                },
                {
                    name: 'Maxmoney',
                    type: 'line',
                    stack: 'Total',
                    areaStyle: {},
                    emphasis: {
                        focus: 'series'
                    },
                    smooth: true,
                    lineStyle:{
                        normal:{
                            width: 3,
                        }
                    },
                    itemStyle: {
                        normal: {
                            borderColor: '#000000',//拐点边框颜色
                            borderWidth: 1//拐点边框大小
                        }
                    },
                    data: []
                },
            ]
        };
        // 定义x、y轴数据数组
        var searchURL = window.location.search;
        searchURL = searchURL.substring(1, searchURL.length);
        var index = searchURL.split("=")[1];
        var workareas=[];
        var avg_minmoneys=[];
        var avg_avgmoneys=[];
        var avg_maxmoneys=[];
        //请求后台数据
        $.ajax({
            type : "post",
            async : true,
            url: "/index/workarea_money/"+index,
            dataType : "json",
            contentType: "application/json",
            success: function(res){
                console.log(res);
                for (var i = 0; i < res.length ; i++) {
                    workareas.push(res[i].workarea);
                    avg_minmoneys.push(res[i].avg_minmoney);
                    avg_avgmoneys.push(res[i].avg_avgmoney);
                    avg_maxmoneys.push(res[i].avg_maxmoney);
                }
                myChart.setOption({
                    xAxis: {
                        data: workareas
                    },
                    series: [{
                        // 根据名字对应到相应的系列
                        name: 'minmoney',
                        data: avg_minmoneys

                    },
                        {
                            // 根据名字对应到相应的系列
                            name: 'maxmoney',
                            data: avg_avgmoneys
                        },
                        {
                            // 根据名字对应到相应的系列
                            name: 'avgmoney',
                            data: avg_maxmoneys
                        },
                    ]
                });
            }
        });
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }
})